/***************************************************************************
 *   This file is part of KLabeler                                         *
 *   Copyright (C) 2010 by Luca Bellonda                                   *
 *   lbellonda _at_ gmail.com                                              *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


#include <kapplication.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <KDE/KLocale>
#include <stdio.h>
#include "ontologymanager.h"

static void printUsage();

static const char description[] =
    I18N_NOOP("A KDE 4 Application to Test klabeler");

static const char version[] = "1.0.0";

int main(int argc, char **argv)
{
    KAboutData about("showtag", 0, ki18n("showtag"), version, ki18n(description),
                     KAboutData::License_GPL, ki18n("(C) 2010 Luca Bellonda"), KLocalizedString(), 0, "lbellonda@gmail.com");
    about.addAuthor(ki18n("Luca Bellonda"), KLocalizedString(), "lbellonda@gmail.com");
    OntologyManager manager;
    manager.start();

    int i = 0;
    int argCount = argc ;
    for (; i < argCount ; i++) {
        if (0 == strcmp(argv[i], "-tagall")) {
            manager.lookForTags();
            return 0;
        }
        if (0 == strcmp(argv[i], "-all")) {
            manager.showAllTags();
            return 0;
        } else if (0 == strcmp(argv[i], "-resource")) {
            if (argCount <= (i + 1)) {
                printUsage();
                return -2;
            }
            manager.showResourceTags(argv[i+1]);
            return 0;
        } else if (0 == strcmp(argv[i], "-tag")) {
            if (argCount <= (i + 1)) {
                printUsage();
                return -2;
            }
            manager.showResourcesOfTags(argv[i+1]);
            return 0 ;
        }
    }
    printUsage();
    return -1;
}

static void printUsage()
{
    printf("usage: showtag -resource \"resource_name\" :shows all resource tags\n");
    printf("     : showtag -tag \"tag_name\" :shows all resources tagged with tag_name\n");
    printf("     : showtag -tagall :shows all tags\n");
}


